package com.example.demo.Spire.DocForJava;

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.ShapeHorizontalAlignment;
import com.spire.doc.ShapeVerticalAlignment;
import com.spire.doc.documents.BookmarksNavigator;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.ParagraphItemType;
import com.spire.doc.documents.TextWrappingStyle;
import com.spire.doc.fields.DocPicture;

import java.io.FileInputStream;
import java.time.Duration;
import java.time.Instant;

public class DocForJava {

    public static void main(String[] args) throws Exception{
        Instant first = Instant.now();
        Document doc = new Document();
        doc.loadFromFile("D:\\zfb_zfsw.doc");
        Instant second = Instant.now();
        System.out.println("创建耗时："+(Duration.between(first,second).toMillis()+"ms"));
        BookmarksNavigator bookmarksNavigator = new BookmarksNavigator(doc);
        bookmarksNavigator.moveToBookmark("gwtitle");
        //bookmarksNavigator.replaceBookmarkContent("您好",false);
        Paragraph paragraph = new Paragraph(doc);
        //图片格式必须是png（反正jpg是不可以的）
        DocPicture docPicture = paragraph.appendPicture(new FileInputStream("D:\\hjw.gif"));
        docPicture.setHeight(20f);
        docPicture.setWidth(60f);
        docPicture.setTextWrappingStyle(TextWrappingStyle.Inline);
        docPicture.setVerticalAlignment(ShapeVerticalAlignment.Center);
        docPicture.setHorizontalAlignment(ShapeHorizontalAlignment.Center);
        paragraph.appendText("2020-12-14");
        bookmarksNavigator.insertParagraph(paragraph);
        bookmarksNavigator.insertText("大家好才是针对额号");
        //============================================================================
        Instant third = Instant.now();
        System.out.println("添加标签耗时："+(Duration.between(second,third).toMillis()+"ms"));
        doc.saveToFile("D:\\output.docx", FileFormat.Docx);
        Instant forth = Instant.now();
        System.out.println("生成文件耗时："+(Duration.between(second,third).toMillis()+"ms"));
    }
}
